package String;

import java.util.Scanner;

public class test1 {
    public static void main(String[] args) {
        //1.定义一个用户名和密码
        String rightName="zhangsan";
        String rightPassword="123456";

        //2.用户登录
        Scanner sc=new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            System.out.println("请输入用户名：");
            String name=sc.next();
            System.out.println("请输入密码");
            String password=sc.next();

            //判断是否登录成功
            if(name.equals(rightName)&&password.equals(rightPassword)){
                System.out.println("登录成功");
                break;
            }else{
                if(i==2){
                    System.out.println("次数用完，账号已锁定");
                }else{
                    System.out.println("登录失败，用户名或密码错误，你还剩下"+(2-i)+"次机会");
                }
            }
        }


    }
}
